package gazzera.swing.download;

import gazzera.swing.model.*;
import gazzera.utils.*;

import java.awt.*;

import javax.swing.*;
import javax.swing.table.*;


public class DownloadSpeedRenderer extends JLabel implements TableCellRenderer {

	private ByteFormatter b =  new ByteFormatter();
	public DownloadSpeedRenderer() {
        super();
        setOpaque(true); 
    }
    

    public Component getTableCellRendererComponent(
                            JTable table, Object o,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        
    	Download c = (Download)o;
 
    	String s = b.formatByteSize(c.speed)+"/s";
    	if(isSelected)
    	{
    		setBackground(table.getSelectionBackground());//new Color(0xb8,0xcf,0xe5));
    	}
    	else
    	{
    		setBackground(table.getBackground());
    	}
    	setForeground(isSelected ? Color.WHITE : Color.BLACK);
        setText(s);
        
        
        return this;
    }
}
